/**
* This file is part of mobileworks.
*
* mobileworks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* You should have received a copy of the GNU General Public License
* along with dev.clipall.  If not, see <http://www.gnu.org/licenses/>.
*
* https://code.google.com/p/mobileworks/
*/

package model.datatypes;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

/**
 *
 * @author Erol Hira
 */
public class MDTStringArray extends MDTBase {
    
    private String[] array;
    
    private int index = -1;
    
    public MDTStringArray(){
        super(STRING_ARRAY);
    }
    
    public MDTStringArray(String[] array){
        this();
        this.array = array;
    }
    
    public void write(DataOutputStream out) throws IOException {
        
        super.write(out);
        
        out.writeInt(array.length);
        
        for(int i = 0; i < array.length; i++){
            out.writeUTF(array[i]);
        }
    }
    
    public void read(DataInputStream in) throws IOException {
        
        super.read(in);
        
        int cnt = in.readInt();
        
        array = new String[cnt];
        
        for(int i = 0; i < cnt; i++){
            
            array[i] = in.readUTF();
        }
    }
    
    public String next(){
        index ++;
        return array[index];
    } 
    
    public void resetIndex(){
        index = -1;
    }
}
